from flask import jsonify, request
from ..services.user_service import UserService
from . import user_bp

@user_bp.route('/users', methods=['POST'])
def create_user():
    data = request.get_json()
    result = UserService.create_user(data)
    return jsonify(result), result.get('status_code', 200)

@user_bp.route('/users', methods=['GET'])
def get_all_users():
    result = UserService.get_all_users()
    return jsonify(result), result.get('status_code', 200)

@user_bp.route('/users/<string:user_id>', methods=['GET'])
def get_user(user_id):
    result = UserService.get_user(user_id)
    return jsonify(result), result.get('status_code', 200)


@user_bp.route('/users/<string:user_id>', methods=['PUT'])
def update_user(user_id):
    data = request.get_json()
    result = UserService.update_user(user_id, data)
    return jsonify(result), result.get('status_code', 200)


@user_bp.route('/users/<string:user_id>', methods=['DELETE'])
def delete_user(user_id):
    result = UserService.delete_user(user_id)
    return jsonify(result), result.get('status_code', 200)
    